import threading
import time

import cv2
from qfluentwidgets import FluentIcon

from ok.feature.FindFeature import FindFeature
from ok.logging.Logger import get_logger


from src.task.BaseXtTask import BaseXtTask

logger = get_logger(__name__)


class TestTask(BaseXtTask,FindFeature):

    def __init__(self):
        super().__init__()
        self.name = "测试任务"
        self.description = "测试任务。。。。"
        self.icon = FluentIcon.SHOPPING_CART
        # self.yc = RotationGIA(debug_enable=True)
        self.login_b_thread=None

    def test_find_power(self):
        if power_box := self.find_one("ys_sr_power2", box=self.get_box_by_name("box_sr_all2")):
            box_sr_right2 = self.box_right_icon_cling(box=power_box, right_box_name='box_sr_right2')
            # texts_tili = self.ocr(box=box_sr_right2)
            # logger.info(f'box_sr_right2：{box_sr_right2}')
            #
            texts_tili = self.ocr(box=self.get_box_by_name("box_sr_all2"))
            logger.info(f'box_sr_right2：{box_sr_right2}')
            if texts_tili:
                logger.info(f'1当前 体力为：{texts_tili}')
                if texts_tili[0].name == "剩余":
                    logger.info(f'2当前 体力为：{texts_tili[len(texts_tili)-1].name}')
                    return texts_tili[0]

                return texts_tili[0]
        return "aaaaaaaaa"

    def trigger(self):
        return True
    def run(self):
        self.next_step = "领取每日委托"
        # self.next_step = "合成树脂"
        # self.align_angle()
        # self.run_to_hct(is_open_map=False)
        # self.load_chars()
        # self.load_chars()
        # self.load_chars()
        # self.get_tili()
        # time.sleep(1)
        # self.check_use(tili="是")
        # self.run_map()
        # self.print_cur_position()
        #         # mp = MiniMap(debug_enable=True)
        # mp.logger.setLevel(logging.INFO)
        # mp.choose_map('层岩巨渊')
        # mp.choose_map('渊下宫')

        # self.print_cur_position()

        # self.run_map_img("ys_hct", "合成")
        # from capture.capture_factory import capture
        # gc = capture
        # gc.add_observer(yc)
        # self.test_e_round()
        # self.test_check_sr()
        # return True
        # while True:
        #     key = cv2.waitKey(20)
        #     if key & 0xFF == ord('q'):
        #         break
        #     # self.next_frame()
        #     # self.turn_to_angle(0)
        #     #
        #     # self.test_angle()

